using UnityEngine;
using UnityEngine.UI;

public class PlayerDodgeCDBar : MonoBehaviour
{
    public Image CD;
    float dodgeCD;

    private void Start() {
        CD.fillAmount = 1;
    }

    // 注册事件监听器
    private void OnEnable()
    {
        PlayerEvents.onUpdateDodgeCD += UpdateDodgeCD;
    }

    // 注销事件监听器
    private void OnDisable()
    {
        PlayerEvents.onUpdateDodgeCD -= UpdateDodgeCD;
    }

    //更新CD UI
    public void UpdateDodgeCD(float dodgeCooldown)
    {
        CD.fillAmount = 0;
        dodgeCD = dodgeCooldown;
    }

    private void Update()
    {
        if(CD.fillAmount == 1) return;
        CD.fillAmount  += Time.deltaTime / dodgeCD;
    }
}

